﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CPPEI.Coolzon.ServiceProxy.DataServiceRef;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    /// <summary>
    /// Interaction logic for DataChartSector.xaml
    /// </summary>
    public partial class DataChartSector : UserControl
    {
        public DataChartSector(double width, double height, double startAngle, double endAngle, string dataItemValue, string dataItemName, int totalItemCount, int indexValue)
        {
            InitializeComponent();

            this.Width = Math.Min(width, height);
            this.Height = Math.Min(width, height);

            this.ArcStartAngle = startAngle;
            this.ArcEndAngle = startAngle;
            this.OffsetAngle = endAngle - startAngle;
            this.ArcMiddleAngle = ArcStartAngle + OffsetAngle / 2 - 270;
            this.ArcNegativeMiddleAngle = ArcMiddleAngle * -1;

            this.DataItemValue = dataItemValue;
            this.DataItemName = dataItemName;
            this.IndexValue = indexValue;
            this.ItemNameVisible = Visibility.Collapsed;
            this.ItemValueVisible = Visibility.Collapsed;
            this.LineVisible = Visibility.Collapsed;
            this.IsLineVisible = false;

            //设置扇形的大小及位置
            double sectorWidth = (this.Width / 2) / totalItemCount * (totalItemCount - (indexValue - 1)) + this.Width / 2;
            double sectorHeight = (this.Height / 2) / totalItemCount * (totalItemCount - (indexValue - 1)) + this.Height / 2;
            this.SectorWidth = sectorWidth * 7 / 10;
            this.SectorHeight = sectorHeight * 7 / 10;
            double topMargin = (this.Width - this.SectorWidth) / 2;
            double leftMargin = (this.Height - this.SectorHeight) / 2;
            this.SectorMargin = new Thickness(topMargin, leftMargin, topMargin, leftMargin);

            this.ValueLabelPadding = new Thickness(this.Width / 3 - SectorWidth / 6, 0, 0, 0);
            this.CenterX = this.Width / 2;
            this.CenterY = this.Height / 2;

            //设置线的位置
            nameLine.X1 = this.Width / 2;
            nameLine.Y1 = this.Height / 2;
            nameLine.X2 = (this.Width - SectorWidth) / 4;
            nameLine.Y2 = this.Height / 2;

            //设置序列数字的位置
            indexLabel.Width = this.Width / 2 - 30;
            indexLabel.Height = this.Height;
            indexLabel.Visibility = Visibility.Collapsed;

            //设置圆环的位置
            arcRing.Margin = new Thickness(this.Width / 2 - 50, this.Height / 2 - 50, this.Width / 2 - 50, this.Height / 2 - 50);

            nameContentLabel.MaxWidth = (this.Width - SectorWidth) *2/ 5;
            contentLabel.Width = this.Width / 8;
            contentLabel.MaxWidth = this.Width / 8;
        }

        public static double j2h(double j)
        {
            return Math.PI * j / 180;
        }
        public static double h2j(double h)
        {
            return h / Math.PI * 180;
        }
    }
}
